import request from "@/request";

// 查询所有电脑信息的接口
export const getComputerList = ()=> {
    return request.get('/computer/getListComputer')
}

//模糊查询电脑的接口
export const getSearchComputer = (computerData)=> {
    //借助于urlSearchParams完成传递
    const params = new URLSearchParams()
    params.append('price',computerData.price)
    params.append('detail',computerData.detail)
    // for (let key in computerData) {
    //     params.append(key,computerData[key])
    // }
    return request.get('/computer/getSearchComputer', {params})
}
//开始上机接口
export const openComputer = (detail)=> {
    console.log("openComputer接口中的detail：" + detail)
    const params = new URLSearchParams()
    params.append('detail',detail)
    return request.put('/computer/insertUsage', params)
}
//查询可用时长和金额的接口
export const findUsableInfo = (detail)=> {
    console.log("findUsableInfo接口中的detail："+detail)
    const params = new URLSearchParams()
    params.append('detail',detail)
    return request.get('/computer/getUsableInfo', {params})
}
//结束 下机接口
export const closeComputer = (detail)=> {
    const params = new URLSearchParams();
    params.append('detail',detail)
    return request.post('/computer/endUseComputer', params)
}

//查询上机历史接口
export const searchUseComputerHistory = ()=> {
    return request.get('/computer/findUsageHistory')
}

//查询指定时间内的上机历史接口
export const searchUseComputerHistoryByTimeToTime = (firstTime,secondTime)=> {
    const params = new URLSearchParams();
    params.append('firstTime',firstTime)
    params.append('secondTime',secondTime)
    return request.get('/computer/findHistoryByTimeToTime', {params})
}

//编辑电脑信息接口
export const editComputer = (computerData)=> {
/*    const params = new URLSearchParams();
    params.append('id',computerData.id)
    params.append('price',computerData.price)
    params.append('detail',computerData.detail)*/
    return request.post('/computerManager/editComputer', computerData)
}

//删除电脑接口
export const deleteComputer = (computerData)=> {
    return request({
        method: 'delete',
        url: '/computerManager/removeComputer',
        data: computerData
    })
}

//添加电脑接口
export const addComputer = (computerData)=> {
    return request.put('/computerManager/addComputer',computerData)
}

//查询使用中电脑信息接口
export const getUsingComputer = ()=> {
    return request.get('/computerManager/getComputerUsageCurrent')
}

//强制下机接口
export const forceCloseComputer = (computerData)=> {
    return request.post('/computerManager/closeUserComputer',computerData)
}

//提醒用户接口
export const sendMessageToUser = (message)=>{
    const params = new URLSearchParams();
    params.append('message',message)
    return request.post('/computerManager/notify',params)
}

//管理员查询所有上机历史接口
export const findAllUsageHistory = (info)=> {
    const params = new URLSearchParams();
    params.append('username',info.username)
    params.append('firstTime',info.firstTime)
    params.append('secondTime',info.secondTime)
    return request.get('/computerManager/managerFindUsageHistory', {params})
}

//管理员删除历史记录接口
export const removeUsageHistory = (id)=>{
    const params = new URLSearchParams()
    params.append('id',id)
    return request.delete('/computerManager/removeComputerUsage',{params})
}

//获取电脑每日收益信息
export const getComputerProfit = ()=>{
    return request.get('/computerManager/getComputerDailyProfit')
}

//获取当日收入
export const getTodayProfit = ()=>{
    return request.get('/computerManager/getTodayProfit')
}

//获取昨日收入
export const getYesterdayProfit = ()=>{
    return request.get('/computerManager/getYesterdayProfit')
}